/*    */ package com.hs.activation.common.utils;
/*    */ 
/*    */ import com.auth0.jwt.JWT;
/*    */ import com.auth0.jwt.algorithms.Algorithm;
/*    */ import com.hs.activation.entity.User;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.springframework.web.context.request.RequestAttributes;
/*    */ import org.springframework.web.context.request.RequestContextHolder;
/*    */ import org.springframework.web.context.request.ServletRequestAttributes;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class JwtUtil
/*    */ {
/*    */   private JwtUtil() {
/* 19 */     throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public static String getToken(User user) {
/* 26 */     return JWT.create().withAudience(new String[] { user.getId().toString()
/* 27 */         }).sign(Algorithm.HMAC256(user.getPassword()));
/*    */   }
/*    */   
/*    */   public static Integer getCurrentUserId() {
/* 31 */     RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
/* 32 */     ServletRequestAttributes sra = (ServletRequestAttributes)requestAttributes;
/* 33 */     HttpServletRequest request = sra.getRequest();
/* 34 */     String token = request.getHeader("token");
/* 35 */     String userId = JWT.decode(token).getAudience().get(0);
/* 36 */     return Integer.valueOf(userId);
/*    */   }
/*    */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\commo\\utils\JwtUtil.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */